/**
 * Created by jy on 2014/8/1.
 */

var crypto=require("crypto");
var _ = require('underscore');

var token = "AbC";
exports.weixinSign = function(options){
  var arr = new Array();
  arr.push(token);
  arr.push(options["timestamp"]);
  arr.push(options["nonce"]);
  arr.sort();
  var msg = arr.join("");
  var shasum = crypto.createHash('sha1');
  shasum.update(msg);
  var hasher=shasum.digest('hex');
  if(_.isEmpty(options["signature"])){
    return false;
  }
  if(options["signature"].toUpperCase() == hasher.toUpperCase()){
    return true;
  }
  return false
};

exports.isValidIdString = function(id){
  if(_.isEmpty(id)){return false;}
  if(_.isString(id)){
    if(id.length === 24){
      return true;
    }
  }
  return false;
};
